package com.lbmb.mdps.commons.exception;

import com.lbmb.mdps.commons.constant.Constant;
import com.lbmb.mdps.commons.domain.ReturnObjectVO;
import com.lbmb.mdps.workbench.domain.Deliver;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 林文塨
 * @date 2022-05-30 2:54
 * description
 */
@ControllerAdvice
public class GlobalExceptionResolver {

    @ExceptionHandler(value = AdministratorException.class)
    @ResponseBody
    public ReturnObjectVO doAdministratorException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = EmployeeException.class)
    @ResponseBody
    public ReturnObjectVO doEmployeeException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = SupplierException.class)
    @ResponseBody
    public ReturnObjectVO doSupplierException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = WarehouseException.class)
    @ResponseBody
    public ReturnObjectVO doWarehouseException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = MedicineTypeException.class)
    @ResponseBody
    public ReturnObjectVO doMedicineTypeException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = MedicineException.class)
    @ResponseBody
    public ReturnObjectVO doMedicineInfoException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = AuditException.class)
    @ResponseBody
    public ReturnObjectVO doAuditException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = PurchaseException.class)
    @ResponseBody
    public ReturnObjectVO doPurchaseException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = InventoryException.class)
    @ResponseBody
    public ReturnObjectVO doInventoryException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = DeliverException.class)
    @ResponseBody
    public ReturnObjectVO doDeliverException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }

    @ExceptionHandler(value = ChartException.class)
    @ResponseBody
    public ReturnObjectVO doChartException(Exception e) {
        ReturnObjectVO rov = new ReturnObjectVO();
        rov.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
        rov.setMessage(e.getMessage());
        return rov;
    }
}
